#include <stdio.h>
#include "../include/Trie.h"
#include <stdlib.h>

Trie* insert_trie_node(char *str, NAryNode *nAryNode)
{

	int i;
	NAryNode *nAryTemp = (NAryNode*)malloc(sizeof(NAryNode));
	nAryTemp->fd = nAryNode->fd;
	nAryTemp->next = NULL;
	if(TrieRoot == NULL)
	{
		Trie *node = (Trie*)malloc(sizeof(Trie));
		node->ch = ' ';
		int j;
		for(j=0; j<26; j++)
			node->children[j] = NULL;
		node->nAryNode = NULL;
		TrieRoot = node;
	}

	Trie *temp = TrieRoot;
	for(i=0;str[i]!='\0';i++)
	{
		int index = (str[i]-'a')%26;
		if(temp->children[index] == NULL)
		{	
			Trie *node = (Trie*)malloc(sizeof(Trie));
			node->ch = str[i];
			int j;
			for(j=0; j<26; j++)
				node->children[j] = NULL;
			node->nAryNode = NULL;
			temp->children[index] = node;	
		}
		temp = temp->children[index];
	}
	nAryTemp->next = temp->nAryNode;
	temp->nAryNode = nAryTemp;

	return temp;
}

Trie* search_trie_node(char *str)
{
	Trie *temp = TrieRoot;
	int i;
	for(i=0;str[i]!='\0';i++)
	{
		int index = (str[i]-'a')%26;
		if(temp->children[index] == NULL)
			return NULL;
		else
			temp = temp->children[index];
	}	
	return temp;
}

/*
	abc.pdf
	abc
	a->Node
	b->Node
	c->Node
	abc.txt	nAryNode->next;
*/
